package antidestiny.java2dex.ui.activity;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Toast;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import antidestiny.java2dex.R;
import antidestiny.utilib.io.FileUtils;

public class AdActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ad);
    }
    public void onclick(View v){
        switch (v.getId()) {
            case R.id.button_save_code:
                Thread thread=new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Bitmap code3 = BitmapFactory.decodeResource(getResources(), R.drawable.code_donate_3);
                        File sdcardpath = Environment.getExternalStorageDirectory();
                        File file3 = new File(sdcardpath + "/zhifubao.jpeg");
                        file3 = FileUtils.createFileSafely(file3, false);
                        FileOutputStream fos3 = null;
                        try {
                            fos3=new FileOutputStream(file3);
                            code3.compress(Bitmap.CompressFormat.JPEG, 100, fos3);
                            AdActivity.this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file3)));

                            AdActivity.this.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(AdActivity.this, "图片写入到卡中去了。", Toast.LENGTH_LONG).show();

                                }
                            });
                             } catch (IOException e){
                            e.printStackTrace();
                        }finally {
                                 try {
                                if (fos3!=null)fos3.close();
                            }
                            catch (IOException e){
                                e.printStackTrace();
                            }
                        }
                    }

                });
                thread.start();

                }
    }

}
